package com.guli.sms.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.guli.sms.entity.HomeSubjectEntity;
import com.guli.sms.service.HomeSubjectService;

import com.guli.common.utils.R;


/**
 * 首页专题表【jd首页下面很多专题，每个专题链接新的页面，展示专题商品信息】
 *
 * @author LuoJunHua
 * @email 1007052116@qq.com
 * @date 2020-11-29 10:59:49
 */
@RestController
@RequestMapping("/sms/homesubject")
public class HomeSubjectController {

    @Autowired
    private HomeSubjectService homeSubjectService;


    @GetMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取homeSubject分页列表")
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size, @RequestParam Map<String, Object> params) {

        Page<HomeSubjectEntity> page = homeSubjectService.queryPage(currentPage, size, params);

        return R.ok().put("page", page);
    }


    @GetMapping("/info/{id}")
    @ApiOperation("根据id获取HomeSubject")
    public R info(@PathVariable("id") Long id) {

            HomeSubjectEntity homeSubject = homeSubjectService.getById(id);

        return R.ok().put("homeSubject", homeSubject);
    }

    @PostMapping("/save")
    @ApiOperation("插入HomeSubject")
    public R save(@RequestBody HomeSubjectEntity homeSubject) {

            homeSubjectService.save(homeSubject);

        return R.ok();
    }

    @PostMapping("/saveBatch")
    @ApiOperation("批量插入HomeSubject")
    @Transactional
    public R saveBatch(@RequestBody List<HomeSubjectEntity> homeSubjectList) {
            homeSubjectService.saveBatch(homeSubjectList);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据id更新HomeSubject")
    public R update(@RequestBody HomeSubjectEntity homeSubject) {
            homeSubjectService.updateById(homeSubject);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据id批量删除HomeSubject")
    public R delete(@RequestBody Long[] ids) {
            homeSubjectService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
